<template>
    <div class="withdrawal-list-container">
        <!-- 搜索筛选区域 -->
        <div class="search-section">
            <el-card shadow="never" class="search-card">
                <div class="search-content">
                    <div class="search-left">
                        <el-form :model="searchForm" :inline="true" class="search-form">
                            <el-form-item label="账号:">
                                <el-input 
                                    v-model="searchForm.account" 
                                    placeholder="输入账号" 
                                    clearable
                                    style="width: 200px"
                                />
                            </el-form-item>
                            <el-form-item label="申请日期:">
                                <el-date-picker
                                    v-model="searchForm.dateRange"
                                    type="daterange"
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期"
                                    style="width: 240px"
                                />
                            </el-form-item>
                        </el-form>
                    </div>
                    <div class="search-right">
                        <el-button type="primary" @click="handleSearch">查询结果</el-button>
                    </div>
                </div>
            </el-card>
        </div>

        <!-- 数据表格区域 -->
        <div class="table-section">
            <el-card shadow="never" class="table-card">
                <el-table 
                    :data="tableData" 
                    v-loading="loading"
                    stripe
                    border
                    style="width: 100%"
                >
                    <el-table-column type="index" label="序号" width="80" align="center" />
                    <el-table-column prop="account" label="账号" />
                    <el-table-column prop="expertName" label="专家名称" />
                    <el-table-column prop="name" label="姓名" />
                    <el-table-column prop="withdrawalMethod" label="提现方式" />
                    <el-table-column prop="withdrawalAmount" label="提现金额" align="right" />
                    <el-table-column prop="applicationTime" label="申请时间" />
                    <el-table-column prop="status" label="状态" align="center">
                        <template #default="{ row }">
                            <el-tag 
                                :type="getStatusType(row.status)"
                                size="small"
                            >
                                {{ row.status }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" width="200" align="center" fixed="right">
                        <template #default="{ row }">
                            <el-button 
                                v-if="row.status === '待审核'" 
                                type="warning" 
                                size="small" 
                                @click="handleAudit(row)"
                            >
                                审核
                            </el-button>
                            <el-button type="danger" size="small" @click="handleDelete(row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-card>
        </div>

        <!-- 分页区域 -->
        <div class="pagination-section">
            <el-card shadow="never" class="pagination-card">
                <div class="pagination-content">
                    <div class="pagination-info">
                        <span>总共{{ pagination.total }}条记录,当前在第{{ pagination.current }}页</span>
                    </div>
                    <el-pagination
                        v-model:current-page="pagination.current"
                        :page-size="pagination.size"
                        :total="pagination.total"
                        :page-sizes="[10, 20, 50, 100]"
                        layout="prev, pager, next, jumper"
                        @current-change="handlePageChange"
                        @size-change="handleSizeChange"
                    />
                </div>
            </el-card>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';

const router = useRouter();

// 搜索表单
const searchForm = reactive({
    account: '',
    dateRange: []
});

// 表格数据
const loading = ref(false);
const tableData = ref([
    {
        id: 1,
        account: '17374558585',
        expertName: '专家1',
        name: '周安',
        withdrawalMethod: '微信',
        withdrawalAmount: '20000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '待审核'
    },
    {
        id: 2,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    },
    {
        id: 3,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '已通过'
    },
    {
        id: 4,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    },
    {
        id: 5,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    },
    {
        id: 6,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    },
    {
        id: 7,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    },
    {
        id: 8,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    },
    {
        id: 9,
        account: '17885878577',
        expertName: '李四',
        name: '周安',
        withdrawalMethod: '银行卡',
        withdrawalAmount: '10000.00',
        applicationTime: '2023/8/20 16:55:22',
        status: '未通过'
    }
]);

// 分页数据
const pagination = reactive({
    current: 7035,
    size: 10,
    total: 140694
});

// 获取状态类型
const getStatusType = (status: string) => {
    switch (status) {
        case '待审核':
            return 'warning';
        case '已通过':
            return 'success';
        case '未通过':
            return 'danger';
        default:
            return 'info';
    }
};

// 搜索方法
const handleSearch = () => {
    loading.value = true;
    // 模拟搜索请求
    setTimeout(() => {
        loading.value = false;
    }, 1000);
};

// 分页方法
const handlePageChange = (page: number) => {
    pagination.current = page;
    loading.value = true;
    // 模拟分页请求
    setTimeout(() => {
        loading.value = false;
    }, 500);
};

const handleSizeChange = (size: number) => {
    pagination.size = size;
    pagination.current = 1;
    loading.value = true;
    // 模拟分页请求
    setTimeout(() => {
        loading.value = false;
    }, 500);
};

// 审核提现
const handleAudit = (row: any) => {
    router.push(`/withdrawal-audit/${row.id}`);
};

// 删除提现
const handleDelete = (row: any) => {
    ElMessageBox.confirm(
        `确定要删除提现记录 "${row.account}" 吗？`,
        '删除确认',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        ElMessage.success('删除成功');
        // 这里可以调用删除API
    }).catch(() => {
        ElMessage.info('已取消删除');
    });
};

// 页面初始化
onMounted(() => {
    // 可以在这里加载初始数据
});
</script>

<style scoped>
.withdrawal-list-container {
    padding: 20px;
}

/* 搜索区域 */
.search-section {
    margin-bottom: 20px;
}

.search-card {
    border-radius: 8px;
}

.search-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-form {
    margin: 0;
}

.search-form .el-form-item {
    margin-bottom: 0;
}

.search-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 表格区域 */
.table-section {
    margin-bottom: 20px;
}

.table-card {
    border-radius: 8px;
}

/* 分页区域 */
.pagination-section {
    margin-bottom: 20px;
}

.pagination-card {
    border-radius: 8px;
}

.pagination-content {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: 20px;
    align-items: center;
}

.pagination-info {
    color: #606266;
    font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .withdrawal-list-container {
        padding: 10px;
    }
    
    .search-content {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .search-form {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .pagination-content {
        flex-direction: column;
        gap: 15px;
        align-items: center;
    }
}
</style>
